<?php
namespace Collect;

class fetchVrData
{

    public function gather()
    {   
        ini_set('memory_limit', '-1');
        $act = request()->param('act');
        switch ($act) {

            case 'get_ivrpano':
            case 'get_gy720':
            case 'get_cnquanjing':
            case 'get_krpano100':
            case 'get_720yunvideo':
            case 'get_panorover':
            case 'get_720think':
            case 'get_expoon':
            case 'get_svsvr':
            case 'get_autohome':
            case 'get_justeasy':

                ignore_user_abort(false);
                $st        = request()->param('st',0);
                $se        = request()->param('se',201);
                $site_name = substr($act, 4);   
                $t_all   = 0;             
                $t_event = 0;
                for ($i = $st; $i < $se; $i++) {
                    $t = call_user_func_array([$this, 'match' . $site_name . 'All'], array($i));
                    $t_all += $t[1];
                    $pct = round($i * 100 / $se);
                    $this->flushEevent(array('site_name' => $site_name, 'pct' => $pct, 't_all' => $t_all), $t_event);
                    $t_event = 1;
                    if (!$t[0]) {
                        break;
                    }

                    if ($i > $st + 10 && $t_all == 0) {
                        break;
                    }
                }
                $this->flushEevent(array('site_name' => $site_name, 'pct' => 100, 't_all' => $t_all), $t_event);
                exit;
                break;
            case 'get_detu':
                $st = request()->param('st',1);
                $t_all     = 0;
                $t_event   = 0;
                $site_name = substr($act, 4);
                $channels  = array(13, 27, 41, 16, 20, 17, 19, 15, 14);
                foreach ($channels as $j) {
                    for ($i = $st; $i < 51; $i++) {
                        $t = call_user_func_array([$this, 'match' . $site_name . 'All'], array($i, $j));
                        $t_all += $t[1];
                        $pct = ceil($j * 100 / 74);
                        $this->flushEevent(array('site_name' => $site_name, 'pct' => $pct, 't_all' => $t_all), $t_event);
                        $t_event = 1;
                        if (!$t[0]) {
                            break;
                        }

                    }
                }
                $this->flushEevent(array('site_name' => $site_name, 'pct' => 100, 't_all' => $t_all), $t_event);
                exit;
          

            case 'get_720yun':

                $site_name = substr($act, 4);
                $channels  = array(45,18,31,46,47,33,11,26,25,27,30,12,34,32,35,36,37,39);
                $t_all     = 0;
                $t_event   = 0;
                foreach ($channels as $key => $channelid) {
                    for ($i = 1; $i < 100; $i++) {
                        $t = call_user_func_array([$this, 'match' . $site_name . 'All'], array($channelid, $i));
                        if (!$t) {
                         $err += 1;
                        }

                        if ($err > 5) {
                            break;
                        }
                        $t_all += $t[1];
                        $pct = ceil(($i /100 +$key) * (100/count($channels)));
                        $this->flushEevent(array('site_name' => $site_name, 'pct' => $pct, 't_all' => $t_all), $t_event);
                        $t_event = 1;
                        if (!$t[0]) {
                            break;
                        }

                    }
                }
                $this->flushEevent(array('site_name' => $site_name, 'pct' => 100, 't_all' => $t_all), $t_event);
                exit;
                break;

            case 'get_720yunAuthor':

                $site_name = substr($act, 4);
                $t_all     = 0;
                $err       = 0;
                $st        = request()->param('st',1);
                $se        = request()->param('se',80);              
                $t_event   = 0;
                for ($i = $st; $i < $se; $i++) {

                    $t = call_user_func_array([$this, 'match' . $site_name . 'All'], array($i));
                    if (!$t) {
                        $err += 1;
                    }

                    if ($err > 5) {
                        break;
                    }

                    $t_all += $t[1];
                    $pct = ($i - $st + 1) * 100 / ($se - $st);
                    $this->flushEevent(array('site_name' => $site_name, 'pct' => (int) $pct, 't_all' => $t_all), $t_event);
                    $t_event = 1;

                }
                $this->flushEevent(array('site_name' => $site_name, 'pct' => 100, 't_all' => $t_all), $t_event);
                exit;
                break;

        }

    }

    private function flushEevent($ar, $i)
    {
     
        if ($i == "0") {
            header('Content-Type: text/event-stream');
            header('Cache-Control: no-cache');
            header('X-Accel-Buffering: no');
            ob_clean();
            ob_end_flush();
            set_time_limit(0);
        }

        $str = json_encode($ar);        
        echo "data:" . $str . "\n\n";
        flush();
        ob_flush();
        sleep(1);
    }

    public function matchivrpanoAll($page)
    {

        $result = array(0, 0);
        $markup = $this->curlSendByPut("https://www.ivrpano.com/ws/vrpic/getpics", array('pageNum' => $page, 'countNum' => 1000, 'stdCls' => "-1", 'PSCls' => "-1", "other" => '-1'));

        if ($markup) {
            $ls  = json_decode($markup, true);
            $ins = 0;
            foreach ((array)$ls['picdata'] as $v) {
                $avatar = $v['absolutelocation'];
                if (strpos($avatar, '/website/images/default-head.png') !== false) {
                    $avatar = 'http://static.ivrpano.com/website/images/default-head.png';
                }
                $s_url = 'http://www.ivrpano.com/ws/openPano/' . $v['view_uuid'];
               
                $item = array(
                    's_title'         => addslashes(strip_tags($v['name'])),
                    's_cover'         => $v['thumb_path'],
                    's_brief'         => addslashes(strip_tags($v['profile'])),
                    's_date'          => date('Y-m-d H:i:s', time() - 86400 * mt_rand(30, 100)),
                    's_author'        => addslashes($v['nickname']),
                    's_author_avatar' => $avatar . '?imageView2/1/w/50/h/50',
                    's_rq'            => $v['browsing_num'],
                    's_tag'           => addslashes(strip_tags($v['keywords'])),
                    's_url'           => 'http://www.ivrpano.com/ws/openPano/' . $v['view_uuid'],
                    's_from'          => 'ivrpano',
                    's_uuid'          => guid(16),
                    'created'         => date('Y-m-d'),
                );
                $ok = $this->insertDb($item);
                $ok && $ins += 1;
            }
            $ls['picdata'] && $result = array(1, $ins);
        }
        return $result;
    }

    public function matchcnquanjingAll($page)
    {

        $result = array(0, 0);
        $page += 1;
        $markup = $this->curlFetch('http://vr.vra.cn/api/frontpano/searchpano', array('pageIndex' => $page, 'pageSize' => 20, 'tag_id' => '', 'keyword' => '', 'user_id' => 0));
        if ($markup) {
            $ls  = json_decode($markup, true);
            $ins = 0;
            foreach ($ls['data']['list'] as $v) {
                $avatar = $v['user_avatar'];
                $s_url  = $v['panoview_url'];
             
                $item = array(
                    's_title'         => addslashes(strip_tags($v['pano_name'])),
                    's_cover'         => $v['icon_src'],
                    's_brief'         => addslashes(strip_tags($v['profile'])),
                    's_date'          => substr($v['addtime'], 0, 10),
                    's_author'        => addslashes($v['user_nickname']),
                    's_author_avatar' => $avatar,
                    's_rq'            => $v['seecount'],
                    's_tag'           => addslashes(strip_tags($v['tag_id'])),
                    's_url'           => $s_url,
                    's_from'          => 'cnquanjing',
                    's_uuid'          => guid(16),
                    'created'         => date('Y-m-d'),
                );

                $ok = $this->insertDb($item);
                $ok && $ins += 1;
            }
            $ls['data'] && $result = array(1, $ins);
        }
        return $result;
    }

    public function match720yunAll($channelid, $page)
    {

        $result = array(0, 0);

        $headers   = array();
        $headers[] = 'Accept:application/json, text/plain, */*';
        $headers[] = 'Accept-Encoding:gzip, deflate, br';
        $headers[] = 'Accept-Language:zh-CN,zh;q=0.8';
        $headers[] = 'App-Authorization:kl3re67jq2l19w9cyr8v0g5xy92wgo4v';
        $headers[] = 'App-Key:eByjUyLDG2KtkdhuTsw2pY46Q3ceBPdT';
        $headers[] = 'Connection:keep-alive';        
        $headers[] = 'Host:apiv4.720yun.com';
        $headers[] = 'Origin:https://720yun.com';
        $headers[] = 'Referer:https://720yun.com/channel';
        $headers[] = 'User-Agent:Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36';
        $markup = $this->curlFetchNew("https://apiv4.720yun.com/products?channelId=" . $channelid . "&page=" . $page . "&selected=2&sort=0", $headers);
        if ($markup) {
            $ls  = json_decode($markup, true);
            $ins = 0;
            foreach ((array) $ls['data']['list'] as $v) {
                $s_url = 'https://720yun.com/t/' . $v['property']['pid'];
               
                $item = array(
                    's_title'         => addslashes(strip_tags($v['property']['name'])),
                    's_cover'         => 'http://thumb-qiniu.720static.com/@' . $v['property']['thumbUrl'] . '?imageMogr2/thumbnail/100',
                    's_brief'         => addslashes(strip_tags($v['property']['remark'])),
                    's_date'          => date('Y-m-d H:i:s', $v['property']['createDate']),
                    's_author'        => addslashes($v['author']['nickname']),
                    's_author_avatar' => 'http://avatar-qiniu.720static.com/@' . $v['author']['avatar'] . '?imageMogr2/thumbnail/220',
                    's_rq'            => $v['pvCount'],
                    's_tag'           => addslashes(strip_tags($v['property']['keywords'])),
                    's_url'           => $s_url,
                    's_from'          => '720yun',
                    's_type'          => 1,
                    's_uuid'          => guid(16),
                    'created'         => date('Y-m-d'),
                );
                $ok = $this->insertDb($item);
                if ($ok) {
                    $ins += 1;
                }

            }
            $markup && $result = array(1, $ins);
        }

        return $result;
    }

    public function match720yunAuthorAll($page)
    {
        $result    = array(0, 0);
        $headers   = array();
        $headers[] = 'Accept:application/json, text/plain, */*';
        $headers[] = 'Accept-Encoding:gzip, deflate, br';
        $headers[] = 'Accept-Language:zh-CN,zh;q=0.8';
        $headers[] = 'App-Authorization:kl3re67jq2l19w9cyr8v0g5xy92wgo4v';
        $headers[] = 'App-Key:eByjUyLDG2KtkdhuTsw2pY46Q3ceBPdT';
        $headers[] = 'Connection:keep-alive';       
        $headers[] = 'Host:apiv4.720yun.com';
        $headers[] = 'Origin:https://720yun.com';
        $headers[] = 'Referer:https://720yun.com/author';
        $headers[] = 'User-Agent:Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36';
        $markup    = $this->curlFetchNew("https://apiv4.720yun.com/authors?page=" . $page . "&province=0&sort=1&type=2", $headers);
        $ins       = 0;
        if ($markup) {
            $ls = json_decode($markup, true);
            if (!$ls) {
                return false;
            }

            foreach ((array) $ls['data']['list'] as $item_p) {
                $jt = 2;
                $j  = 0;
                if (!$item_p['uid']) {
                    continue;
                }

                while ($j <= $jt) {
                    $j++;
                    $tmp = $this->curlFetchNew("https://apiv4.720yun.com/author/" . $item_p['uid'] . "/products?sort=0&page=" . $j . "&selected=2", $headers);
                    if (!$tmp) {
                        break;
                    }

                    $item_data = json_decode($tmp, true);

                    if (!$item_data || !$item_data['data']['list']) {
                        break;
                    }

                    $jt      = ceil($item_data['data']['count'] / 32);
                    $item_ls = $item_data['data']['list'];
                    foreach ((array) $item_ls as $k => $v) {
                        $s_url = 'https://720yun.com/t/' . $v['property']['pid'];
                        
                        $item = array(
                            's_title'         => addslashes(strip_tags($v['property']['name'])),
                            's_cover'         => 'http://thumb-qiniu.720static.com/@' . $v['property']['thumbUrl'] . '?imageMogr2/thumbnail/100',
                            's_brief'         => addslashes(strip_tags($v['property']['remark'])),
                            's_date'          => date('Y-m-d H:i:s', $v['property']['updateDate'] ? $v['property']['updateDate'] : time()),
                            's_author'        => addslashes($item_p['nickname']),
                            's_author_avatar' => 'http://avatar-qiniu.720static.com/@' . $item_p['avatar'] . '?imageMogr2/thumbnail/220',
                            's_rq'            => $v['pvCount'],
                            's_tag'           => addslashes(strip_tags($v['property']['keywords'])),
                            's_url'           => $s_url,
                            's_from'          => '720yun',
                            's_type'          => 1,
                            's_uuid'          => guid(16),
                            'created'         => date('Y-m-d'),
                        );

                        $ok = $this->insertDb($item);

                        if ($ok) {
                            $ins += 1;
                        }

                        sleep(0);
                    }

                }

            }
            $result = array(1, $ins);
        }

        return $result;
    }

    public function match720yunvideoAll($page)
    {

        $result = array(0, 0);
        $markup = $this->curlFetch("https://ssl-api.720yun.com/api/video/list/" . $page);
        if ($markup) {
            $ls  = json_decode($markup, true);
            $ins = 0;
            foreach ($ls as $v) {
                $s_url = 'https://720yun.com/v/' . $v['vid'];
               
                $item = array(
                    's_title'         => addslashes(strip_tags($v['name'])),
                    's_cover'         => $v['mobile_thumb'] . '?imageView2/2/w/100/h/100/q/100',
                    's_brief'         => addslashes(strip_tags($v['desc'])),
                    's_date'          => date('Y-m-d H:i:s', $v['update_date']),
                    's_author'        => addslashes($v['member_nickname']),
                    's_author_avatar' => $v['member_avatar'],
                    's_rq'            => $v['pv'],
                    's_tag'           => addslashes(strip_tags($v['keywords'])),
                    's_url'           => $s_url,
                    's_from'          => '720yun',
                    's_type'          => 2,
                    's_uuid'          => guid(16),
                    'created'         => date('Y-m-d'),
                );
                $ok = $this->insertDb($item);
                if ($ok) {
                    $ins += 1;
                }

            }
            $item && $result = array(1, $ins);
        }

        return $result;
    }

    public function matchkrpano100All($page)
    {

        $result = array(0, 0);
        $markup = file_get_contents("http://demo.krpano100.com/pictures?act=list&tag=0&page={$page}");
        if ($markup) {
            $ls  = json_decode($markup, true);
            $ins = 0;
            foreach ($ls as $v) {
                $s_url = 'http://demo.krpano100.com/tour/' . $v['view_uuid'];
               
                $item = array(
                    's_title'         => addslashes(strip_tags($v['name'])),
                    's_cover'         => $v['thumb_path'],
                    's_brief'         => addslashes(strip_tags($v['profile'])),
                    's_date'          => date('Y-m-d H:i:s', time() - 86400 * mt_rand(30, 100)),
                    's_author'        => '优视全景',
                    's_author_avatar' => 'http://demo.krpano100.com/plugin/custom_logo/images/custom_logo.png',
                    's_rq'            => $v['browsing_num'],
                    's_tag'           => '',
                    's_url'           => $s_url,
                    's_from'          => 'krpano100',
                    's_uuid'          => guid(16),
                    'created'         => date('Y-m-d'),
                );
                $ok = $this->insertDb($item);
                $ok && $ins += 1;

            }
            $ls && $result = array(1, $ins);
        }
        return $result;
    }

    public function matchdetuAll($page, $channelid)
    {

        $result = array(0, 0);
        $markup = file_get_contents("http://www.detu.com/ajax/collection/getChannelList?page={$page}&pagesize=12&channelid={$channelid}");
        if ($markup) {
            $ls  = json_decode($markup, true);
            $ins = 0;
            foreach ($ls['data'] as $v) {
                $s_url = 'http://www.detu.com/pano/show/' . $v['relationid'];
               
                $item = array(
                    's_title'         => addslashes(strip_tags($v['name'])),
                    's_cover'         => $v['thumb'],
                    's_brief'         => addslashes(strip_tags($v['summary'])),
                    's_date'          => $v['releasetime'],
                    's_author'        => addslashes($v['user']['nickname']),
                    's_author_avatar' => $v['user']['headphoto'],
                    's_rq'            => $v['pano']['viewcount'],
                    's_tag'           => '',
                    's_url'           => $s_url,
                    's_from'          => 'detu',
                    's_uuid'          => guid(16),
                    'created'         => date('Y-m-d'),
                );
                $ok = $this->insertDb($item);
                $ok && $ins += 1;
            }
            $ls['data'] && $result = array(1, $ins);
        }
        return $result;
    }

    public function matchgy720All($page)
    {

        $result = array(0, 0);
        $markup = $this->curlFetch('https://www.gy720.com/pano?page=' . $page);
        if ($markup) {
            require_once  root_path().'/extend/phpQuery-onefile.php';
            $hobj = \phpQuery::newDocumentHTML($markup);
            $lt   = pq($hobj)->find('.pano-item');
            $t    = time();
            $ins  = 0;
            foreach ($lt as $v) {
                $s_url = trim(pq($v)->attr('href'));
               
                $item = array(
                    's_title'         => addslashes(str_replace(array(' ', "\t", "\n", "\r"), '', pq($v)->find('.pano-item-title')->text())),
                    's_cover'         => pq($v)->find('.pano-item-img>img')->attr('data-original'),
                    's_brief'         => '......',
                    's_date'          => date('Y-m-d H:i:s', $t - (86400 * mt_rand(10, 100))),
                    's_author'        => addslashes(pq($v)->find('.pano-item-author-avatar>img')->attr('alt')),
                    's_author_avatar' => pq($v)->find('.pano-item-author-avatar>img')->attr('data-original'),
                    's_rq'            => trim(str_replace('', '', pq($v)->find('.pano-item-collect>span')->text())),
                    's_tag'           => '',
                    's_url'           => $s_url,
                    's_from'          => 'gy720',
                    's_uuid'          => guid(16),
                    'created'         => date('Y-m-d'),
                );
                $ok = $this->insertDb($item);
                $ok && $ins += 1;
            }
            $markup && $result = array(1, $ins);
        }
        return $result;
    }

   

    public function matchpanoroverAll($page)
    {
        $result    = array(0, 0);
        $prefix    = "https://panorover.com/";
        $headers   = array();
        $headers[] = 'Accept:application/json, text/plain, */*';
        $headers[] = 'Accept-Encoding:gzip, deflate, br';
        $headers[] = 'Accept-Language:zh-CN,zh;q=0.8';
        $headers[] = 'Connection:keep-alive';
        $headers[] = 'Referer:https://panorover.com/Pano';
        $headers[] = 'User-Agent:Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36';
        $markup    = $this->curlFetchNew($prefix . "Api/Panos?page=" . $page . "&pageSize=10&sort=Id&order=desc&field=Title", $headers);
        if ($markup) {
            $ls  = json_decode($markup, true);
            $ins = 0;
            foreach ($ls['data'] as $v) {

                $s_url = $prefix . 'P/' . trim($v['key']);
               
                $item = array(
                    's_title'         => addslashes(strip_tags($v['title'])),
                    's_cover'         => str_replace('/0/0/0/0/', '/200/200/1/0/', $v['firstImage']['url']),
                    's_brief'         => addslashes(strip_tags($v['title'])),
                    's_date'          => substr($v['addTime'], 0, 10),
                    's_author'        => addslashes($v['user']['nickName']),
                    's_author_avatar' => str_replace('/0/0/0/0/', '/200/200/1/0/', $v['user']['avatarUrl']),
                    's_rq'            => $v['viewCount'],
                    's_tag'           => '',
                    's_url'           => $s_url,
                    's_from'          => 'panorover',
                    's_uuid'          => guid(16),
                    'created'         => date('Y-m-d'),
                );

                $ok = $this->insertDb($item);
                $ok && $ins += 1;
            }
            $ls['data'] && $result = array(1, $ins);
        }
        return $result;
    }

    public function match720thinkAll($page)
    {

        $result = array(0, 0);
        $prefix = 'http://www.720think.com/';
        $markup = file_get_contents($prefix . 'index.php?g=think720&m=home&a=getPanoramaList&sort=0&pageIndex=' . $page . '&pageSize=100');
        if ($markup) {
            $ls  = json_decode($markup, true);
            $ins = 0;
            foreach ($ls['list'] as $v) {
                $tags    = $v['Tags'];
                $vt_tags = array();
                foreach ($v['tagList'] as $vt) {
                    $vt_tags[] = $vt['content'];
                }
                $s_url = $prefix . 't/' . $v['shor_url_id'];
               
                $item = array(
                    's_title'         => addslashes(strip_tags($v['name'])),
                    's_cover'         => $v['thumburl'],
                    's_brief'         => addslashes(strip_tags($v['vppDetail']['description'])),
                    's_date'          => substr($v['create_time'], 0, 10),
                    's_author'        => addslashes($v['memberDetail']['nickname']),
                    's_author_avatar' => $v['memberDetail']['headimgurl'],
                    's_rq'            => $v['pv'],
                    's_tag'           => implode(',', $vt_tags),
                    's_url'           => $s_url,
                    's_from'          => '720think',
                    's_uuid'          => guid(16),
                    'created'         => date('Y-m-d'),
                );
                $ok = $this->insertDb($item);
                $ok && $ins += 1;
            }
            $ls['list'] && $result = array(1, $ins);
        }
        return $result;
    }

    public function matchquanjingkeAll($page)
    {

        $result = array(0, 0);
        $prefix = 'http://www.quanjingke.com/';
        $markup = file_get_contents($prefix . 'index.php?m=dest&c=dest_photo&ajax=1&pn=' . $page);
        if ($markup) {
            $ls = json_decode($markup, true);
            foreach ($ls as $v) {
                $s_url = $prefix . 'krpano/krpano.swf?xml=http://www.quanjingke.com/oxml.php?picid=' . $v['id'];
               
                $item = array(
                    's_title'         => addslashes(strip_tags($v['title'])),
                    's_cover'         => 'https://www.quanjingke.com/statics/images/2012/dest/logo.jpg',
                    's_brief'         => addslashes(strip_tags($v['des'])),
                    's_date'          => substr(date('Y-m-d', $v['inputtime']), 0, 10),
                    's_author'        => addslashes($v['nick']),
                    's_author_avatar' => $v['userimg'],
                    's_rq'            => $v['viewcount'],
                    's_tag'           => implode(',', $vt_tags),
                    's_url'           => $s_url,
                    's_from'          => 'quanjingke',
                    's_uuid'          => guid(16),
                    'created'         => date('Y-m-d'),
                );
                $ok = $this->insertDb($item);
                $ok && $ins += 1;
            }
            $ls && $result = array(1, $ins);
        }
        return $result;
    }

    public function matchexpoonAll($page)
    {

        $result = array(0, 0);
        $markup = $this->curlFetch('http://www.expoon.com/pano/p' . $page . '.html');
        if ($markup) {
            require_once  root_path().'/extend/phpQuery-onefile.php';
            $hobj = \phpQuery::newDocumentHTML($markup);
            $lt   = pq($hobj)->find('.subList');
            $t    = time();
            $ins  = 0;
            foreach ($lt as $v) {
                $s_url = 'http:' . pq($v)->find('a:eq(0)')->attr('href');
               
                $item = array(
                    's_title'         => addslashes(pq($v)->find('a:eq(1)')->text()),
                    's_cover'         => pq($v)->find('a:eq(0)>img')->attr('src'),
                    's_brief'         => '......',
                    's_date'          => date('Y-m-d H:i:s', $t - (86400 * mt_rand(10, 100))),
                    's_author'        => '网展',
                    's_author_avatar' => 'http://s.expoon.com/image/201512/home/index/logo.jpg',
                    's_rq'            => mt_rand(1, 100),
                    's_tag'           => '',
                    's_url'           => $s_url,
                    's_from'          => 'expoon',
                    's_uuid'          => guid(16),
                    'created'         => date('Y-m-d'),
                );
                $ok = $this->insertDb($item);
                $ok && $ins += 1;
            }
            $markup && $result = array(1, $ins);
        }
        return $result;
    }

    public function matchsvsvrAll($page)
    {

        $result = array(0, 0);
        $markup = file_get_contents("http://www.svsvr.com/pictures?act=list&page={$page}");
        if (preg_match('/^\xEF\xBB\xBF/', $markup)) {
            $markup = substr($markup, 3);
        }
        if ($markup) {
            $ls  = json_decode($markup, true);
            $ins = 0;
            foreach ($ls as $v) {
                $s_url = 'http://www.svsvr.com/tour/' . $v['view_uuid'];
               
                $item = array(
                    's_title'         => addslashes(strip_tags($v['name'])),
                    's_cover'         => $v['thumb_path'],
                    's_brief'         => addslashes(strip_tags($v['profile'])),
                    's_date'          => date('Y-m-d H:i:s', time() - 86400 * mt_rand(30, 100)),
                    's_author'        => '超视景',
                    's_author_avatar' => 'http://www.svsvr.com/plugin/custom_logo/images/custom_logo.png',
                    's_rq'            => $v['browsing_num'],
                    's_tag'           => '',
                    's_url'           => $s_url,
                    's_from'          => 'svsvr',
                    's_uuid'          => guid(16),
                    'created'         => date('Y-m-d'),
                );
                $ok = $this->insertDb($item);
                $ok && $ins += 1;

            }
            $ls && $result = array(1, $ins);
        }
        return $result;
    }

//720yun数据解析
    public function matchjusteasyAll($page)
    {

        $result = array(0, 0);
        $page += 1;
        $markup = $this->curlFetch('https://vr.justeasy.cn/panos-0-0-0-0.html?page=' . $page);

        if ($markup) {
            require_once  root_path().'/extend/phpQuery-onefile.php';
            $hobj = \phpQuery::newDocumentHTML($markup);
            $lt   = pq($hobj)->find("li.list");
            $t    = time();
            $ins  = 0;

            foreach ($lt as $v) {

                $s_url = trim(pq($v)->find(".pic>a")->attr('href'));

                $title = addslashes(trim(pq($v)->find(".pic>a>img")->attr('title')));
                $item  = array(
                    's_title'         => $title,
                    's_cover'         => trim(pq($v)->find(".pic>a>img")->attr('src')),
                    's_brief'         => $title,
                    's_date'          => date('Y-m-d H:i:s', $t - (86400 * mt_rand(10, 100))),
                    's_author'        => '建E全景',
                    's_author_avatar' => trim(pq($v)->find(".photo>a>img")->attr('src')),
                    's_rq'            => (int) pq($v)->find(".icon-vr-ll")->text(),
                    's_tag'           => '建E全景',
                    's_url'           => $s_url,
                    's_from'          => 'justeasy',
                    's_uuid'          => guid(16),
                    'created'         => date('Y-m-d'),
                );

                $ok = $this->insertDb($item);
                $ok && $ins += 1;
            }

            $markup && $result = array(1, $ins);
        }
        return $result;
    }

//汽车之家
    public function matchautohomeAll($page)
    {

        $result = array(0, 0);
        $index  = (int) ($page + 2);
        $markup = $this->curlFetch('https://car.autohome.com.cn/vr/ajax/getListByPage/?type=0&order=2&brandId=0&seriesId=0&topnum=16&pageIndex=' . $index);
        if ($markup) {
            require_once  root_path().'/extend/phpQuery-onefile.php';
            $hobj = \phpQuery::newDocumentHTML($markup);
            $lt   = pq($hobj)->find('a');
            $t    = time();
            $ins  = 0;
            foreach ($lt as $v) {
                $s_url = trim(pq($v)->attr('href'));
               

                $item = array(
                    's_title'         => addslashes(pq($v)->find('dd>p')->eq(0)->text()),
                    's_cover'         => pq($v)->find('dt>img')->attr('src'),
                    's_brief'         => addslashes(pq($v)->find('dd>p')->eq(1)->text()),
                    's_date'          => date('Y-m-d H:i:s', $t - (86400 * mt_rand(10, 100))),
                    's_author'        => '汽车之家',
                    's_author_avatar' => 'http://x.autoimg.cn/car/images/vr/vr-logo.png',
                    's_rq'            => (int) pq($v)->find('dd>p')->eq(2)->text(),
                    's_tag'           => '汽车之家',
                    's_url'           => $s_url,
                    's_from'          => 'autohome',
                    's_uuid'          => guid(16),
                    'created'         => date('Y-m-d'),
                );
                $ok = $this->insertDb($item);
                $ok && $ins += 1;
            }
            $markup && $result = array(1, $ins);
        }
        return $result;
    }

/**
 * 获取远程数据
 * @param  [type] $url  [目标网址]
 * @param  [type] $data [发送数据]
 * @return [type]       [发送类型]
 */
    public function curlFetch($url, $data = null)
    {
        $agent = "Mozilla/5.0 (Linux; U; Android 4.2.2; zh-cn; Nibiru H1 Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 MicroMessenger/5.3.0.80_r701542.440";
        
        $result = qCurl($url,$data,['headers'=>['agent'=>$agent]]);       
        return $result;
    }

    public function curlSendByPut($url, $data = array())
    {
        $json   = json_encode($data);
        $header = array(
            'Accept:application/json, text/javascript, */*; q=0.01',
            'Accept-Encoding:gzip,deflate',
            'Accept-Language:zh-CN,zh;q=0.8',
            'Connection:keep-alive',
            'Host:www.ivrpano.com',
            'Referer:http://www.ivrpano.com/ws/opensearch/',
            'X-Requested-With:XMLHttpRequest',
            'Content-Type: application/json',

        );
        $useragent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36';
        $curl      = curl_init(); // 启动一个CURL会话
        curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
        curl_setopt($curl, CURLOPT_HTTPHEADER, $header); //设置HTTP头字段的数组
        curl_setopt($curl, CURLOPT_ENCODING, '');
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); // 从证书中检查SSL加密算法是否存在
        curl_setopt($curl, CURLOPT_USERAGENT, $useragent); // 模拟用户使用的浏览器
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
        curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
        curl_setopt($curl, CURLOPT_HTTPGET, 1); // 发送一个常规的GET请求
        curl_setopt($curl, CURLOPT_TIMEOUT, 10); // 设置超时限制防止死循环
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
        curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
        $r = curl_exec($curl);
        curl_close($curl);
        return $r;
    }

    public function curlFetchNew($url, $headers, $data = null)
    {
        $r = qCurl($url,$data,['headers'=>$headers]);

        $r = gzdecode($r);

        return $r;
    }

    private function insertDb($item)
    {
        return \think\facade\Db::connect("kr_search")->name('search')->extra('IGNORE')->insert($item);
    }

}
